<link rel="help" href="http://www.w3.org/TR/2013/WD-2dcontext2-20130528/#dom-context-2d-setlinedash">
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body>
<script>
test(function(t) {
    
    var canvas = document.createElement('canvas');
    document.body.appendChild(canvas);
    canvas.setAttribute('width', '700');
    canvas.setAttribute('height', '700');
    var ctx = canvas.getContext('2d');
    
    var arrayValues = [5, 15, 25];
    
    function createIterableObject() {
      return {
        [Symbol.iterator]() {
          var i = 0;
          return {
            next() {
              if (i >= arrayValues.length)
                return { done: true };
              return { done: false, value: arrayValues[i++] };
            }
          }
        }
      }
    }

    function createTestArray(arrayType) {
      var array;
      if (arrayType == Object) {
        array = createIterableObject();
      } else {
        array = new arrayType(arrayValues.length);
        for (var i = 0; i < arrayValues.length; ++i)
          array[i] = arrayValues[i];
      }
      return array;
    }

    var lineDash;
    var inputArray;
    function checkLineDash(testArray, shouldFail) {
        inputArray = testArray;
        // Reset line dash.
        ctx.setLineDash([]);
        // Set line dash.
        if (shouldFail) {
          assert_throws_js(TypeError, function() {
            ctx.setLineDash(inputArray);
          });
        } else {
            ctx.setLineDash(inputArray);
            lineDash = ctx.getLineDash();
            for (var i = 0; i < arrayValues.length; ++i)
                assert_equals(lineDash[i], arrayValues[i]);
        }
    }

    var arrayTypes = [Array, Int8Array, Int16Array, Int32Array, Uint8Array, Uint16Array, Uint32Array, Float32Array, Float64Array, Uint8ClampedArray, Object];

    // Success cases.
    for (var i = 0; i < arrayTypes.length; ++i) {
        // Test passing a valid array time as input.
        checkLineDash(createTestArray(arrayTypes[i]), false);
    }

    // Failure cases.
    // Test passing a Date as input.
    checkLineDash(new Date(), true);
    // Test passing a RegExp as input.
    checkLineDash(new RegExp(), true);
    // Test passing an Object without length as input.
    checkLineDash({test: 1}, true);
    // Test passing a Number as input.
    checkLineDash(3, true);
    // Test passing a String as input.
    checkLineDash("Test", true);
    // Test passing a Boolean as input.
    checkLineDash(true, true);
    // Test passing null as input.
    checkLineDash(null, true);
    // Test passing undefined as input.
    checkLineDash(undefined, true);

}, 'Test that setLineDash converts input argument into a Web IDL sequence');
</script>
</body>
